package com.jsbj.user.controller;


import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.user.entities.SysLoginRecord;
import com.jsbj.user.service.ISysLoginRecordService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-login_record")
@ApiIgnore
public class SysLoginRecordController extends BaseController {

    @Autowired
    private ISysLoginRecordService sysLoginRecordService;

    @ApiOperation("通过用户登陆手机号查询登录记录（多个id，用逗号分开）")
    @PostMapping("/getLoginRecordByPhoneNum")
    public ResultBean<List<SysLoginRecord>> getLoginRecordByPhoneNum(@RequestParam String phoneNums) {
        String[] phoneNum = phoneNums.split(",");
        return new ResultBean<List<SysLoginRecord>>(sysLoginRecordService.getLoginRecordByPhoneNum(Arrays.asList(phoneNum)));
    }

    @ApiOperation("单项目-最近访问")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户编码", required = true)}
    )
    @PostMapping("/recentVisits")
    public ResultBean<Map<String, Object>> recentVisits() {
        return new ResultBean<Map<String, Object>>(sysLoginRecordService.recentVisits());
    }

    @ApiOperation("单项目-使用情况")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户编码", required = true)}
    )
    @PostMapping("/useCase")
    public ResultBean<Map<String, Object>> useCase() {
        return new ResultBean<Map<String, Object>>(sysLoginRecordService.useCase());
    }
}

